const API = require("../../API/http.js");

Page({
  data: {
    Chinese:[],
    Europe:[],
    Japanese:[],
    Korean:[],
    cantonese:[],
    offset:0
  },
  onLoad:function(){
    wx.showToast({
      title: '加载中',
      icon:"loading"
    });
    API.getLanguage("华语").then(res=>{
      this.setData({
         Chinese: this.handleData(res)
      })
    });
     API.getLanguage("欧美").then(res => {
        this.setData({
           Europe: this.handleData(res)
        })
     });
     API.getLanguage("日语").then(res => {
        this.setData({
           Japanese: this.handleData(res)
        })
     });
     API.getLanguage("韩语").then(res => {
        this.setData({
           Korean: this.handleData(res)
        })
     });
     API.getLanguage("粤语").then(res => {
        this.setData({
           cantonese: this.handleData(res)
        })
     });
  },
  /* 处理请求成功的数据 */
  handleData(res){
    var playlists = res.playlists;
    // console.log(imgUrl)
    var music = [];
    for (var i = 0; i < 35; i++) {
        var obj = {};
        obj.coverImgUrl = playlists[i].coverImgUrl;
        obj.playCount = playlists[i].playCount;
        obj.playCount = obj.playCount>100000?parseInt(obj.playCount/10000)+'万':obj.playCount;
        obj.name = playlists[i].name;
        obj.nickname = playlists[i].creator.nickname;
        obj.id = playlists[i].id;
        music.push(obj);
    }
   return music;
  },
  
 /* 点击前往歌单详情页面 */ 
 onclick(event){
  var {id} = event.currentTarget.dataset;
  console.log(id);
  wx.navigateTo({
    url: '/pages/detail/detail?id='+id,
  })
},

onReachBottom(){
  wx.showToast({
    title: '加载中',
    icon: 'loading',
    duration: 1500,
    mask: false,
  });
  var offset = this.data.offset;
  offset+=35;
  API.getMore("华语",offset).then(res=>{
    var Chinese = this.handleData(res);
    this.setData({
      offset,
      Chinese:this.data.Chinese.concat(Chinese)
    })
  })
}


})
